﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace LeapSample
{
    class MainViewModel : INotifyPropertyChanged
    {
        private LeapModel Model = new LeapModel();
        private SynchronizationContext Context = SynchronizationContext.Current;

        public MainViewModel()
        {
            this.Model.PropertyChanged += Model_PropertyChanged;
        }

        public TItem Item
        {
            get
            {
                return this.Model.Item;
            }
            set
            {
                this.Model.Item = value;
            }
        }

        public void LeapStart()
        {
            this.Model.LeapStart();
        }

        public void LeapStop()
        {
            this.Model.LeapStop();
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged([CallerMemberName] String propertyName = "")
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            this.Context.Post((o) =>
                {
                    OnPropertyChanged(e.PropertyName);
                },
                null);
        }
    }
}
